package com._51cto.healthy.controller;

import com._51cto.healthy.content.P;
import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Disease;
import com._51cto.healthy.service.DiseaseService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("disease")
public class DiseaseController {
    @DubboReference
    private DiseaseService diseaseService;

    @GetMapping("/page/{pageSize}/{pageNum}")
    public R findPage(@RequestParam(value = "query",required = false)String query,
                      @PathVariable("pageSize")Integer pageSize,
                      @PathVariable("pageNum")Integer pageNum){
        P<Disease> disease = diseaseService.findDisease(query, pageSize, pageNum);
        return R.success(disease);

    }
    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id")Integer id){
        diseaseService.deleteByPK(id);
        return R.success("删除成功");
    }
    @PostMapping
    public R insert(@RequestBody Disease disease){
        diseaseService.insert(disease);
        return R.success("添加成功");
    }
    @PutMapping
    public R update(@RequestBody Disease disease){
        diseaseService.update(disease);
        return R.success("修改成功");
    }
}
